/*
(function () {
    $.ajaxSetup({
        complete:function(XMLHttpRequest,textStatus){
            if(textStatus=="parsererror"){
                window.location.href = '/p/user/login';
            }
        }
    });
})();
*/



//原来的代码  =====================================
function countTime() {
    //获取当前时间
    var TimeOut = $('#TimeOut').val();
    var date = new Date();
    var now = date.getTime();
    //设置截止时间
    var endDate = ConvertDateFromString(TimeOut);
    // var endDate = new Date('2017-06-15 10:23:00');
    var end = endDate.getTime();
    //时间差
    var leftTime = end - now;
    //定义变量 d,h,m,s保存倒计时的时间
    var d, h, m, s;
    if (leftTime >= 0) {
        m = Math.floor(leftTime / 1000 / 60 % 60);
        s = Math.floor(leftTime / 1000 % 60);
    }
    // alert(m);alert(s);
    //将倒计时赋值到div中
    document.getElementById("_m").innerHTML = m + ":";
    document.getElementById("_s").innerHTML = s;
    // if(m==1 && s==0){
    // 	layer.msg('离考试结束还剩一分钟哦，请抓紧时间',{icon: 5,time:2000});
    // }
    // if(m==0 && s==0){
    // 	layer.msg('考试时间结束，即将交卷',{icon: 5,time:2000});
    // 	setTimeout(function(){EndTest(3);},2000);
    // 	return false;
    // }
    //递归每秒调用countTime方法，显示动态时间效果
    setTimeout(countTime, 1000);
};


function ConvertDateFromString(dateString) {
    if (dateString) {
        var arr1 = dateString.split(" ");
        var sdate = arr1[0].split('-');
        var tdate = arr1[1].split(':');
        var date = new Date(sdate[0], sdate[1], sdate[2], tdate[0], tdate[1], tdate[2] - 3);
        return date;
    }
};

function formatDateTime(timeStamp) {
    var date = new Date();
    date.setTime(timeStamp * 1000);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '-' + m + '-' + d;
};


//取消转义
function escape2Html(str) {
    if(str){
        var arrEntities = {'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"'};
        return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) {
            return arrEntities[t];
        });
    }

}

//字体闪烁定时器
var shansuoInterval;
function showJiqiao() {
    //显示正确答案
    $(".exam-answer").show();
    //显示技巧文字,并闪烁
    if ($('.DaAnHtml').html()) {
        $('.DaAnText').hide();
        $('.DaAnHtml').show();
        $(".exam-describe").show();
        //新数据
        var $mySpan = $(".exam2-1 span[style^='color'],.exam-describe span[style^='color']");
        //旧数据
        var $shanSuoClassNames = $(".cs1D53A76,.cs866BD963");
        var time = 0;
        shansuoInterval = setInterval(function () {
            time++;
            if(time>=6 && shansuoInterval ){
                clearInterval(shansuoInterval);
                $mySpan.each(function () {
                    $(this).css("visibility",  "visible" );
                });
                $shanSuoClassNames.each(function () {
                    $(this).css("visibility", "visible");
                });
            }
            $mySpan.each(function () {
                $(this).css("visibility", ((time % 2 == 0) ? "visible" : "hidden"));
            });
            $shanSuoClassNames.each(function () {
                $(this).css("visibility", ((time % 2 == 0) ? "visible" : "hidden"));
            });
        }, 700);
    }
}
function closeJiqiao(){
    $('.DaAnText').show();
    $('.DaAnHtml').hide();
    $(".exam-describe").hide();
    if(shansuoInterval){
        clearInterval(shansuoInterval);
    }
}


//==============================================
$(function () {
    var a=0;
    $(".exam2-3").delegate("img,video", "click", function (e) {
        if ($(this).attr("src")) {
            if(!$(this).data("imgWH")){
                var img = new Image();
                img.src = $(this).attr("src");
                $(this).data("imgWH",{"w":img.width,"h":img.height});
            };
            layer.open({
                type: 2,
                title: false,
                area: [$(this).data("imgWH")["w"] , $(this).data("imgWH")["h"]],
                closeBtn: 0,
                skin: 'layui-layer-nobg',
                shadeClose: true,
                content: $(this).attr("src")
            });

        }

    });

});